//
//  CItemPreView.h
//  HCHK_iphone
//
//  Created by yilong zhang on 11-12-7.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "CCommentary.h"
#import "CDisCellView.h"
#import "CMainPageCtrl.h"

@class CMainPageCtrl;
@class CPreItem;

//================================================================================================================================

typedef enum {left, right, none}Direction;

//================================================================================================================================

@protocol PreItemDelegate <NSObject>

@optional
-(void)DidPreItemBtnClicked:(int)tag Object:(CPreItem*)object;

@end

//================================================================================================================================

#define PAGE_HEIGHT     375//310//295
#define PAGE_WIDTH      290//294
#define PANEL_WIDTH     290//275
#define PANEL_HEIGHT    375//258
#define IMAGE_HEIGHT    320//180
#define IMAGE_WIDTH     269//160
//#define ICON_WIDTH      104
//#define ICON_HEIGHT     128

@interface CPreItem : UIView <ProductDelegate>


@property (nonatomic, assign) id<PreItemDelegate>   delegate;

@property (nonatomic, assign) UIView        *m_RootPanel;  
@property (nonatomic, assign) UILabel       *m_PdctName;
@property (nonatomic, assign) UILabel       *m_ResName;
@property (nonatomic, assign) UILabel       *m_ResAddr;
@property (nonatomic, assign) UIImageView   *m_Local;
@property (nonatomic, assign) UILabel       *m_Distance;
@property (nonatomic, assign) UIButton      *m_MoreComsBtn;
@property (nonatomic, assign) UILabel       *m_PubNamelb;
@property (nonatomic, assign) UILabel       *m_PdtSum;
@property (nonatomic, assign) UIButton      *m_DelBtn;
@property (nonatomic, assign) UIButton      *m_NiceBtn;
@property (nonatomic, assign) UIButton      *m_WantBtn;
@property (nonatomic, assign) UIImageView   *m_Image;
@property (nonatomic, assign) UIButton      *m_ImageBtn;
@property (nonatomic, assign) UIView        *m_Drawer;
@property (nonatomic, assign) UIButton      *m_DrawerBtn;
@property (nonatomic, assign) UIButton      *m_ShareBtn;
@property (nonatomic, assign) UIButton      *m_ChangeBtn;
@property (nonatomic, assign) CProduct      *m_Product;
@property (nonatomic, assign) BOOL          m_bIsFavorite;
@property (nonatomic, assign) BOOL          m_bIsImageNull;


-(id)initWithFrame:(CGRect)frame;
-(void)OpenDrawer;
-(void)DidDrawerOpened:(id)object;
-(void)SetInfo:(CProduct*)product ID:(int)id;
-(double)GetLocationDistance:(CLLocationCoordinate2D)cur New:(CLLocationCoordinate2D)new;
-(void)OnButtonDown:(UIButton*)sender;
-(void)LoadImage;

@end

//================================================================================================================================

@protocol ItemPreViewDelegate <NSObject>

-(void)DidPreViewScrollEnd:(id)object;
-(void)PreViewDidSelected:(int)index Object:(CPreItem*)object;
-(void)PreViewDidPublisherInfo;
-(void)PreViewDidWritenCom:(int)state;
-(void)PreViewDidEndDecelerating:(int)index Directory:(int)directory Object:(CPreItem*)object;
-(void)PreViewTapImage:(UIImage*)image;

@end

//================================================================================================================================
@interface  UIScrollViewEx : UIScrollView

//

@end

//================================================================================================================================

@interface CItemPreView : UIView <UIScrollViewDelegate, PreItemDelegate>

@property (nonatomic, assign) id<ItemPreViewDelegate>   m_delegate;

@property (nonatomic, assign) UIScrollView      *m_RootPanel;
@property (nonatomic, assign) Direction         m_Direction;
@property (nonatomic, assign) CPreItem          *m_Loading;
@property (nonatomic, assign) CGPoint           m_Offset;
@property (nonatomic, assign) int               m_nCurIndex;

-(void)InitItemPreView;
-(void)SetItems:(NSArray*)items;
-(void)ShowLoading;
-(void)HiddenLoading;
-(void)ReSetItemPreView;
-(CPreItem*)LoadImages:(int)index;

@end


@interface UIImageView (SetImage)

- (void)SetImageWithAnimation:(UIImage *)image Animation:(BOOL)animation;

@end
